<template>
  <div class="loginBackground">
    <div class="loginForm mt20">
      <div class="contentCenter">
        <span>管理员登录</span>
      </div>
      <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px">
        <el-form-item label="账号" prop="loginName">
          <el-input type="text" v-model="ruleForm.loginName"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input type="password" v-model="ruleForm.password" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div class="contentCenter">
        <el-button type="primary" @click="submitForm('ruleForm')">登录</el-button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
    name: 'Login',
    data() {
        return {
            ruleForm: {
                loginName: '',
                password: ''
            },
            rules: {
                loginName: [
                    { required: true, message: '请输入账号' },
                    { min: 2, max: 32, message: '长度在 2 到 32 个字符' }
                ],
                password: [
                    { required: true, message: '请输入密码' },
                    { min: 3, max: 32, message: '长度在 3 到 32 个字符' }
                ]
            }
        };
    },
    methods: {
        submitForm(formName) {
            this.$refs[formName].validate(valid => {
                if (valid) {
                    this.loginUser(this.ruleForm);
                } else {
                    return false;
                }
            });
        },
        async loginUser(data) {
            const res = await this.postJSON(this.$urlApi.adminLogin, data);
            console.log(res);
        }
    }
};
</script>

<style scoped>
.loginForm {
    width: 400px;
    min-width: 400px;
    clear: both;
}
.loginBackground {
    background: url('~@/assets/image/login.jpg');
    width: 100%;
    height: -webkit-fill-available;
    overflow: hidden;
    position: relative;
}
</style>
